package fms.services;

import java.io.File;
import java.io.FileInputStream;
import java.io.FileOutputStream;
import java.io.IOException;
import java.util.Properties;

public class PropertyTool {
	
private static final String prefix = ".fms";
	
    public static Properties loadProperty(String fileName) throws IOException{
        Properties pros = new Properties();
        File file = null;
        String home = System.getProperty("user.home");
        file = new File(home+File.separator+prefix+File.separator+fileName);
        pros.loadFromXML(new FileInputStream(file));
        return pros;
    }
    
    public static void saveProperty(Properties pros,String fileName) throws IOException{
        String home = System.getProperty("user.home");
        File file = new File(home+File.separator+prefix+File.separator+fileName);
        pros.storeToXML(new FileOutputStream(file),"FMS Config File");
    }
    
    public static void createProperty(Properties pros,String fileName) throws IOException{
        String home = System.getProperty("user.home");
        File dir = new File(home+File.separator+prefix);
        dir.mkdir();
        dir = new File(dir.getAbsolutePath()+File.separator+fileName);
        dir.createNewFile();
        pros.storeToXML(new FileOutputStream(dir),"FMS Config File");
    }
}
